﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using MigratorCore.Actions;

namespace MigratorWizard
{
    public partial class Details : UserControl
    {
        public Details()
        {
            InitializeComponent();
        }

        private Main main;

        public Main Main { set { main = value; main.NextClick += new NextClick(main_NextClick); } }

        void main_NextClick(object sender, EventArgs e)
        {
            if (Visible)
                MessageBox.Show("Make sure you have backed up the database(s)", "Database Backup", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        private void Details_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible && main != null)
            {
                this.main.EnableNext = true;
                this.main.EnableBack = true;
                this.main.Text = "The Migrator Project - Migration Details";
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(string.Format("This Migration will be from {0} to {1} using:", main.Migrator.Source.Name, main.Migrator.Destination));
                sb.AppendLine("   Source's settings:");
                for (int x = 0; x < main.Migrator.Source.Settings.Count; x++) {
                    sb.AppendLine(string.Format("       {0}: {1}", x + 1, main.Migrator.Source.Settings.Keys[x]));
                    sb.AppendLine(string.Format("            {0}", main.Migrator.Source.Settings[x]));
                }
                sb.AppendLine("   Source's Actions:");
                for (int x = 0; x < main.Migrator.SourceActions.Count; x++)
                {
                    sb.AppendLine(string.Format("   {0}: {1}({2}), Settings:", x + 1, main.Migrator.SourceActions[x].Name, main.Migrator.SourceActions[x].ActionType.ToString()));
                    for (int n = 0; n < main.Migrator.SourceActions[x].Settings.Count; n++)
                    {
                        sb.AppendLine(string.Format("       {0}: {1}", n+1, main.Migrator.SourceActions[x].Settings.Keys[n]));
                        sb.AppendLine(string.Format("            {0}", main.Migrator.SourceActions[x].Settings[n]));
                    }
                }
                sb.AppendLine("   Destination's settings:");
                for (int x = 0; x < main.Migrator.Destination.Settings.Count; x++)
                {
                    sb.AppendLine(string.Format("       {0}: {1}", x+1, main.Migrator.Destination.Settings.Keys[x]));
                    sb.AppendLine(string.Format("            {0}", main.Migrator.Destination.Settings[x]));
                }
                sb.AppendLine("   Destination's Actions:");
                for (int x = 0; x < main.Migrator.DestinationActions.Count; x++)
                {
                    sb.AppendLine(string.Format("   {0}: {1}({2}), Settings:", x + 1, main.Migrator.DestinationActions[x].Name, main.Migrator.DestinationActions[x].ActionType.ToString()));
                    for (int n = 0; n < main.Migrator.DestinationActions[x].Settings.Count; n++)
                    {
                        sb.AppendLine(string.Format("       {0}: {1}", n+1, main.Migrator.DestinationActions[x].Settings.Keys[n]));
                        sb.AppendLine(string.Format("            {0}", main.Migrator.DestinationActions[x].Settings[n]));
                    }
                }
                text.Text = sb.ToString();
            }

        }
    }
}
